package models;

import java.sql.SQLException; 
import java.util.Date;

import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.misc.RuntimeExceptionBaseDaoEnabled;
import com.j256.ormlite.table.DatabaseTable;

/**
 * This class holds the information of the tasks that has been created.
 * @author Grishma Patel
 *
 */
@SuppressWarnings("unused")
@DatabaseTable(tableName = "tasks")
public class Task extends RuntimeExceptionBaseDaoEnabled<Task, Integer> 
{
// Grishma, check your fields, names, and types -- they're not quite right based on the CRC cards we made ;-)
// We had at least these fields (non-foreign that is)
//		dueDate
//		createdAt
//  	description
//  	comments
//  	teaser
//  	completed
//  	doesRecur
// Updated: redid fields
	
	
	//Instance Data
	@DatabaseField(generatedId = true)
	private int id;
	
	@DatabaseField
	private String teaser;
	
	@DatabaseField
	private String description;
	
	@DatabaseField
	private String comments;
	
	@DatabaseField
	private Date dueDate;
	
	@DatabaseField
	private Date createdAt;
	
	@DatabaseField
	private boolean completed;
	
	@DatabaseField
	private boolean doesRecur;
	
	@DatabaseField
	private int priority;
	
	@DatabaseField(canBeNull = false, foreignAutoRefresh = true, foreign = true)
    private User user;
	
	@DatabaseField(canBeNull = true, foreignAutoRefresh = true, foreign = true)
    private Category category;
	
	@DatabaseField(canBeNull = true, foreignAutoRefresh = true, foreign = true)
    private Location location;

	// For ORMLite DAO access
	private static RuntimeExceptionDao<Task, Integer> defaultDao = null;
	public static void setDefaultDao(RuntimeExceptionDao<Task, Integer> dao) {
		defaultDao = dao;
	}
	/**
	 * Getter for the database access object
	 * @return defaultDao
	 */
	public static RuntimeExceptionDao<Task, Integer> getDefaultDao() {
		return defaultDao;
	}

	/**
	 * Zero-arg constructor, specifically for ORMlite
	 * @throws SQLException 
	 */
	public Task() {
		super();
		setDao(defaultDao);
	}

	/**
	 * Constructor method for task that initializes all the variables
	 * @param teaser
	 * @param description
	 * @param comments
	 * @param dueDate
	 * @param completed
	 * @param doesRecur
	 */
	public Task(String teaser, String description, String comments,
			Date dueDate, boolean completed, boolean doesRecur) {
		super();
		setDao(defaultDao);
		this.teaser = teaser;
		this.description = description;
		this.comments = comments;
		this.dueDate = dueDate;
		this.completed = completed;
		this.doesRecur = doesRecur;
	}
	/**
	 * Getter for User 
	 * @return user
	 */
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	/**
	 * Getter for category
	 * @return category
	 */
	public Category getCategory() {
		return category;
	}
	
	/**
	 * Setter for category
	 * @param category
	 */
	public void setCategory(Category category) {
		this.category = category;
	}
	
	/**
	 * Getter for location
	 * @return location
	 */
	public Location getLocation() {
		return location;
	}
	
	/**
	 * Setter for location
	 * @param location
	 */
	public void setLocation(Location location) {
		this.location = location;
	}
	
	/**
	 * Getter for teaser
	 * @return teaser
	 */
	public String getTeaser() {
		return teaser;
	}
	
	/**
	 * Setter for teaser
	 * @param teaser
	 */
	public void setTeaser(String teaser) {
		this.teaser = teaser;
	}
	/**
	 * Getter for description
	 * @return description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * Setter for description
	 * @param description
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * Getter for comments
	 * @return comments
	 */
	public String getComments() {
		return comments;
	}
	
	/**
	 * Setter for comments
	 * @param comments
	 */
	public void setComments(String comments) {
		this.comments = comments;
	}
	
	/**
	 * Getter for dueDate
	 * @return dueDate
	 */
	public Date getDueDate() {
		return dueDate;
	}
	
	/**
	 * Setter for dueDate
	 * @param dueDate
	 */
	public void setDueDate(Date dueDate) {
		this.dueDate = dueDate;
	}
	
	/**
	 * Getter to see if the task is completed
	 * @return completed
	 */
	public boolean isCompleted() {
		return completed;
	}
	
	/**
	 * Setter to change the status of a task
	 * @param completed
	 */
	public void setCompleted(boolean completed) {
		this.completed = completed;
	}
	
	/**
	 * Getter to see it the task recurse 
	 * @return doesRecur
	 */
	public boolean isDoesRecur() {
		return doesRecur;
	}
	
	/**
	 * Setter to set recurse
	 * @param doesRecur
	 */
	public void setDoesRecur(boolean doesRecur) {
		this.doesRecur = doesRecur;
	}

	public int getPriority() {
		return priority;
	}
	public void setPriority(int priority) {
		this.priority = priority;
	}
	public String toString() {
		return teaser;
	}
}
